﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Kwan.Web;
using System.Linq;
using BG.Data;

namespace BG.Service.Ext
{
    public class ModuleUnit
    {
        

        

        
    }

    #region 用户页面菜单
    public class PageAuthority
    {
        /// <summary>
        /// 主键
        /// </summary>
        public virtual string Id { get; set; }

        /// <summary>
        /// 并发控制标识
        /// </summary>
        public virtual Int32 Version { get; private set; }

        /// <summary>
        /// 数据创建时间
        /// <remarks>归档用，不可与业务时间混用</remarks>
        /// </summary>
        public virtual DateTime CreateTime { get; private set; }
        /// <summary>
        /// 编码
        /// </summary>
        public virtual string Code { get; set; }
        /// <summary>
        /// 名称
        /// </summary>
        public virtual string Text { get; set; }
        /// <summary>
        /// 父节点
        /// </summary>
        public virtual string Parent { get; set; }
        /// <summary>
        /// 是否叶
        /// </summary>
        public virtual bool IsLeaf { get; set; }
        /// <summary>
        /// 深度
        /// </summary>
        public virtual int NodeLevel { get; set; }
        /// <summary>
        /// 节点组
        /// </summary>
        public virtual string TreeIds { get; set; }
        /// <summary>
        /// 描述
        /// </summary>
        public virtual string Description { get; set; }
        /// <summary>
        /// Area
        /// </summary>
        public virtual string Area { get; set; }
        /// <summary>
        /// Controller
        /// </summary>
        public virtual string Controller { get; set; }
        /// <summary>
        /// Action
        /// </summary>
        public virtual string Action { get; set; }
        /// <summary>
        /// 图标16
        /// </summary>
        public virtual string IconCss16 { get; set; }
        /// <summary>
        /// 图标24
        /// </summary>
        public virtual string IconCss24 { get; set; }
        /// <summary>
        /// 图标48
        /// </summary>
        public virtual string IconCss48 { get; set; }
        /// <summary>
        /// 排序
        /// </summary>
        public virtual int IndexField { get; set; }
        /// <summary>
        /// 是否隐藏
        /// </summary>
        public virtual bool IsHide { get; set; }
        /// <summary>
        /// 模块Id
        /// </summary>
        public virtual string PageId { get; set; }
        /// <summary>
        /// 是否禁用
        /// </summary>
        public virtual bool IsDisable { get; set; }

        ///// <summary>
        ///// 包含的Role
        ///// </summary>
        //public virtual ISet<SysRole> Roles { get; set; }

        public static IList<PageAuthority> GetTestList()
        {
            Dictionary<string, object> cacheModule = UserUtil.GetModule(UserUtil.GetCookieRole());
            var moduleList = (TModule.status > 0 & TModule.nameEN.In(cacheModule.Keys)).List<TModule>();

            var list = new List<PageAuthority>();
            foreach (var item in moduleList)
            {
                bool isLeaf = item.Pid > 0;
                list.Add(new PageAuthority { Id = item.EntityID.ToString(), Parent = item.Pid.ToString(), Text = item.NameCN, IconCss16 = item.NameEN + "16", IconCss24 = item.NameEN + "24", IconCss48 = item.NameEN + "48", PageId = isLeaf ? "/Admin/page/" + item.NameEN + "/Default.aspx" : "0", IsLeaf = isLeaf, NodeLevel = isLeaf ? 2 : 1 });
            }
            return list;
        }

    }

    public class ExtTreeNode<T>
    {
        public string id { get; set; }
        public string text { get; set; }
        public string iconCls { get; set; }
        public bool leaf { get; set; }
        public virtual int level { get; set; }
        public virtual string treeid { get; set; }
        public virtual IList<T> children { get; set; }
    }

    public class ExtCheckTreeNode
    {
        public string id { get; set; }
        public string text { get; set; }
        public string iconCls { get; set; }
        public bool leaf { get; set; }
        public bool Checked { get; set; }
        public bool expanded { get; set; }
        public virtual IList<ExtCheckTreeNode> children { get; set; }
    }

    public class PageAuthorityTree : ExtTreeNode<PageAuthorityTree>
        {
            public string name { get; set; }
            public string code { get; set; }
            public string area { get; set; }
            public string controller { get; set; }
            public string action { get; set; }
            public int indexField { get; set; }
            public bool isDisable { get; set; }
            public bool isHide { get; set; }
            public string icon1 { get; set; }
            public string icon2 { get; set; }
            public string icon3 { get; set; }
            public string winId { get; set; }
        }
        
        
    /// <summary>
    /// 我的桌面快捷方式
    /// </summary>
    public class MyShortcut
    {
        ///// <summary>
        ///// 用户
        ///// </summary>
        //public virtual SysUser User { get; set; }
        /// <summary>
        /// 主键
        /// </summary>
        public virtual string Id { get; set; }

        /// <summary>
        /// 并发控制标识
        /// </summary>
        public virtual Int32 Version { get; private set; }

        /// <summary>
        /// 数据创建时间
        /// <remarks>归档用，不可与业务时间混用</remarks>
        /// </summary>
        public virtual DateTime CreateTime { get; private set; }
        /// <summary>
        /// 页面权限
        /// </summary>
        public virtual PageAuthority Page { get; set; }

        /// <summary>
        /// 模块ID
        /// </summary>
        public virtual string PageId { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public virtual int IndexField { get; set; }
    }
    #endregion
}
